<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> {$action} | {:get_opinion('title')}</title>

    <include file="Public:head"/>

</head>
<body class="skin-blue">

{:W('Common/header')}

<div class="wrapper row-offcanvas row-offcanvas-left">
    {:W('Common/sideMenu')}


    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">
        <!-- Content Header (Page header) -->


        <section class="content-header">
            <h1>
                {$action}
                <small>{:get_opinion('title')}</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{$module_url}"><i class="fa fa-dashboard"></i> {$module}</a></li>
                <li class="active">{$action}</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="row">
                <div class="col-md-12">

                    <!-- /.box-header -->
                    <div class="box-body">


                        <h4>数据库中共有{$list|count}张表，共计{$totalsize.table}&nbsp;&nbsp;&nbsp;&nbsp;
                        </h4>
                        <!-- BEGIN EXAMPLE TABLE PORTLET-->
                        <form id="form">
                            <table
                                    class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th style="width: 8px;">选择</th>
                                    <th>表名</th>
                                    <th class="hidden-240">表用途</th>
                                    <th class="hidden-480">记录行数</th>
                                    <th class="">引擎类型</th>
                                    <th class="">字符集</th>
                                    <th class="">碎片</th>
                                    <th class="">表大小</th>
                                    <th class="">数据</th>
                                    <th class="">索引</th>
                                </tr>
                                </thead>
                                <tbody id="cache_table">
                                <volist name="list" id="tab">
                                    <tr align="center">
                                        <td><input type="checkbox" class='groupclass' name="table[]"
                                                   value="{$tab.Name}"/>
                                        </td>
                                        <td align="left">{$tab.Name}</td>
                                        <td>{$tab.Comment}</td>
                                        <td>{$tab.Rows}</td>
                                        <td>{$tab.Engine}</td>
                                        <td>{$tab.Collation}</td>
                                        <td>{$tab.Data_free}</td>
                                        <td>{$tab.size}</td>
                                        <td>{$tab.Data_length}</td>
                                        <td>{$tab.Index_length}</td>
                                    </tr>
                                </volist>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <th style="width: 8px;">总计</th>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><b>{$totalsize.free}</b></td>
                                    <td><b>{$totalsize.table}</b></td>
                                    <td><b>{$totalsize.data}</b></td>
                                    <td><b>{$totalsize.index}</b></td>
                                </tr>
                                </tfoot>
                            </table>
                            <div class="form-actions margin ">
                                <div class="row margin">
                                    <button type="button" class="btn btn-success optimize">
                                        <i class="m-icon-swapright m-icon-white"></i>优化所选表
                                    </button>

                                    <button type="button" class="btn btn-success repair">
                                        <i class="m-icon-swapright m-icon-white"></i>修复所选表
                                    </button>

                                    <button type="button" class="btn btn-primary" id="checkall">全选</button>


                                    <button type="button" class="btn btn-danger" id="check_cancel">取消</button>


                                    <!--<button type="button" class="btn btn-info" id="check_reverse">反选</button>-->


                                    <span style="font-size:18px;color:red;font-weight:bold;" id="success"></span>
                                </div>
                            </div>
                            <input type="hidden" name="act" id="act"/>
                        </form>

                    </div>
                </div>
            </div>

        </section>
        <!-- /.content -->
    </aside>
    <!-- /.right-side -->
</div>
<!-- ./wrapper -->

<include file="Public:foot"/>
<script type="text/javascript" src="__PUBLIC__/share/js/jquery.form.js"></script>

<script>
    jQuery(document).ready(function () {
        $("#cache_table :checkbox").attr("checked", true);
        $("div").addClass("checked");


        $("#checkall").click(function () { //":checked"匹配所有的复选框
            $("#cache_table :checkbox").attr("checked", true); //"#div1 :checked"之间必须有空格checked是设置选中状态。如果为true则是选中fo否则false为不选中
            $("div").addClass("checked");
        });
        $("#check_cancel").click(function () {
            $("#cache_table :checkbox").attr("checked", false);
            $("div").removeClass("checked");
        });
//        //理解用迭代原理each（function(){}）
        $("#check_reverse").click(function () {
            $("#cache_table :checkbox").each(function () {

                $(this).attr("checked", !$(this).attr("checked"));
                $(this).parentsUntil('div').attr("checked", !$(this).attr("checked"));

                //!$(this).attr("checked")判断复选框的状态：如果选中则取反
            });
        });

        var handle = function (act) {
            if ($("tbody input[type='checkbox']:checked").size() == 0) {
                popup.alert("请先选择数据表");
                return false;
            }
            $("#act").val(act);
            var url = "{:U('Admin/Data/repair')}";
            var formObj = $("#form");
            var div = $("#success");
            //commonAjaxSubmit(url, form, div);
            formObj.ajaxSubmit({
                url: url,
                type: "POST",
                dataType: "json",
                success: function (data) {
                    //                var data = eval("(" + data + ")");
                    if (data.status == 1) {
                        /*popup.success(data.info);
                         setTimeout(function(){
                         popup.close("asyncbox_success");
                         },2000);*/
                        //alert(data.info);
                        div.fadeIn().html(data.info);
                        div.fadeOut(3000);

                    } else {
                        /*popup.error(data.info);
                         setTimeout(function(){
                         popup.close("asyncbox_error");
                         },2000);*/
                        //alert(data.info);
                        div.fadeIn().html(data.info);
                        div.fadeOut(5000);
                    }
                    if (data.url && data.url != '') {
                        setTimeout(function () {
                            top.window.location.href = data.url;
                        }, 1000);
                    }
                    if (data.url == '') {
                        setTimeout(function () {
                            top.window.location.reload();
                        }, 1000);
                    }
                }
            });
        }
        $(".optimize").click(function () {
            $(".optimize").attr("disabledSubmit", false).html("处理中，请稍后...");

            handle("optimize");
        });
        $(".repair").click(function () {
            $(".repair").attr("disabledSubmit", false).html("处理中，请稍后...");

            handle("repair");
        });
    });
</script>
</body>
</html>